#ifndef FACTORY_H
#define FACTORY_H

#include "Singleton.h"
#include "NonCopyable.h"
#include <map>
#include <string>


template <class T>
class Factory : public NonCopyable
{
private:
	Factory(){}
	friend class Singleton<Factory>;
public:
	typedef T* (*Function) ();
	T* Create(const std::string& name)
	{
		Function f = m_map[name];
		if (f)
		{
			return f();
		}
		return 0;
	}

	bool AddType(const std::string& name, Function f)
	{
		m_map[name] = f;
		return true;
	}
private:
	typedef std::map<std::string, Function> FactoryMap;

	FactoryMap m_map;
};


#endif
